Skip to content

Conversation

@AngledLuffa
Copy link
Contributor

Add functionality to semgrex to search for/against key/value pairs in fields on words which are maps. Currently the one thing which this really applies to is morphofeatures. When searching on morphofeatures, it matches a key string, then checks that the value does or doesn't match.

Current syntax:

{morphofeatures:{k1:/v1/;k2!:/v2/}}

represents a morphofeatures that must have k1=v1, but k2 != v2. /.../ represents regex, whereas not having /.../ would force an exact match.

…s which are Maps.

Currently the syntax is @, subject to change

eg,

morphofeatures@foo=bar

In this expression, bar can be a regex, but foo and morphofeatures cannot.
It might be worth adding regex capabilities for both of those,
Also, !@ would be a useful addition.

This checks at Semgrex compile time (not Java compile time) that
the annotation used for key/value is actually a Map

Has a test that the error checking and a simple search both work.
Need to negate the = in the NodePattern output
This map allow repeated elements inside the same brackets
@AngledLuffa
Copy link
Contributor Author

Discussed syntax with @manning , happy with current status

@AngledLuffa AngledLuffa merged commit 3c30b3b into dev Mar 6, 2025
1 check passed
@AngledLuffa AngledLuffa deleted the semgrex_contains branch March 6, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants